#  author:张靖昆 date:2020/3/12 name:test IDE:PyCharm
import  re
from  datetime import  datetime,timedelta

# 日期切割-作业
date01='2020-3-11 9:10:30'
res =re.findall(r'\d{1,4}',date01)
print(res)

#把下面的代码封装到函数中
def turn01(infos):
    for item in infos:
        time_now = datetime.now()
        time_str=item['time']
        rn = re.findall(r'\d{1,2}', time_str)
        if len(rn)>0:
            n=int(rn[0])
        else:
            n=0
        if '小时' in time_str:
            time = time_now + timedelta(hours=-n)
        elif '分钟' in time_str:
            time = time_now + timedelta(minutes=-n)
        elif '天' in time_str:
            time = time_now + timedelta(days=-n)
        else:
            time = time_now
        item['time']=time.strftime('%Y-%m-%d %H:%M:%S')
    print(infos)

